package org.wak.dialog
{
	import org.wak.utils.ArrayIterator;
	import org.wak.utils.IIterator;
	
	/**
	 * Data structure for dialog between two characters in the adventure.  
	 * 
	 */	
	public class AdventureDialog
	{
		private var mTopicsArray:Array = null ;
		
		
		// Id of the dialog.
		private var mDialogId:String = "" ;
		
		//startup topic
		private var mStartupTopic:Topic = null ;
		
		/**
		 * Constructor 
		 * @param pDialogInput input xml with the dialog.
		 * 
		 */		
		public function AdventureDialog( pDialogInput:XML)
		{
			mTopicsArray = new Array ;
			
			mDialogId = pDialogInput.@id ;
			mStartupTopic = new Topic(pDialogInput.Startup.Topic[0]) ;
			
			var fNewTopic:Topic = null ;
			for each( var topic:XML in pDialogInput.Topic )
			{
				fNewTopic = new Topic( topic );
				mTopicsArray.push(fNewTopic);
				//trace(fNewTopic);
			}
			
		}
		
		/**
		 * Test if a character is present in the dialog. The entry topic is
		 * excluded. 
		 * @param pCharId Character id.
		 * @return true if the character in pCharId is present in the dialog.
		 * 
		 */		
		public function isPresent(pCharId:String):Boolean
		{
			for each(var topic:Topic in mTopicsArray)
			{
				if(topic.isPresent(pCharId) )
					return true ;
			}
			return false ;
		}
		
		/**
		 * Topics of the dialog 
		 * @return IIterator of the topics
		 * 
		 */		
		public function GetTopics():IIterator
		{
			return new ArrayIterator( mTopicsArray );
		}
		
		/**
		 * id of this dialog. 
		 * @return String with the dialog id.
		 * 
		 */		
		public function get dialogId():String 
		{
			return mDialogId ;
		}
		
		/**
		 * The startup topic or entry point to the conversation. 
		 * @return Dialog topic to play when the conversation starts and before the dialog options are shown.
		 * 
		 */		
		public function get startupTopic():Topic
		{
			return mStartupTopic ;
		}

	}
}